package com.yuerlive.rainbow.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.view.View;

import com.yuerlive.rainbow.API;
import com.yuerlive.rainbow.R;

import java.text.DecimalFormat;


/**
 * Created by Admin on 2017/6/5.
 */

public class Utils {
    public static void setLevel(View v , int level){
        if (level <= 1) {
            v.setBackgroundResource(R.drawable.badge_1);
        } else if (level > 1 && level <= 12) {
            v.setBackgroundResource(R.drawable.badge_2);
        } else if (level > 12 && level <= 22) {
            v.setBackgroundResource(R.drawable.badge_3);
        } else {
            v.setBackgroundResource(R.drawable.badge_4);
        }
    }
    public static void setLiveAudienceLevel(View v,int level){
        if (level <= 1) {
            v.setBackgroundResource(R.drawable.badge_small_1);
        } else if (level > 1 && level <= 12) {
            v.setBackgroundResource(R.drawable.badge_small_2);
        } else if (level > 12 && level <= 22) {
            v.setBackgroundResource(R.drawable.badge_small_3);
        } else {
            v.setBackgroundResource(R.drawable.badge_small_4);
        }
    }
    public  static String filterUrl(String url) {
        if (url == null) return "";
        if (url.startsWith("http://") || url.startsWith("https://")) {
            //L.e(TAG, url);
            return url;
        } else {
            return API.IMAGE_HOST + url;
        }
    }

    /**
     * 禁止按钮的快速点击
     *
     * @return
     */
    public static boolean isFastDoubleClick(long lastClickTime) {
        long time = System.currentTimeMillis();
        if (time - lastClickTime < 500) {
            return true;
        }
        return false;
    }

    /**
     * 禁止按钮的快速点击
     *
     * @return
     */
    public static boolean  isFastDoubleClick(int toastTime,long lastClickTime) {
        long time = System.currentTimeMillis();
        if (time - lastClickTime < toastTime) {
            return true;
        }
        return false;
    }
    public static int checkAPP(Context context) {
        try {
            PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(),
                            PackageManager.GET_SIGNATURES);
            Signature[] signs = packageInfo.signatures;
            Signature sign = signs[0];

            int hashcode = sign.hashCode();
            L.e("test", "hashCode : " + hashcode);
            return hashcode == -82892576 ? 1 : 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return -1;
    }
    public static String getFormartNum(int num){
        float num2=0.0f;
        if(num/10000>0){
            num2=num/10000f;
        }else{
            return  num+"";
        }
        DecimalFormat df   =new DecimalFormat("#.0");
        return  df.format(num2)+"万";
    }
}
